// 导出 request 函数
// request 函数 返回 fetch promise对象数据
// 参数
// 类型
// import qs from "qs";
import qs from "webopenfather-qs";

// const baseURL = "https://wip.myifashop.com";
const baseURL = "https://comfyideals.myifashop.com";
// const baseURL = "/api";

export const request = <T>(
  path: string,
  options: REQUEST.Options
): Promise<T> => {
  const { params = {}, method = "GET", headers = {}, body = null } = options;

  let temp = "";
  if (Object.keys(params).length) {
    temp = "?" + qs.stringify(params);
  }

  return fetch(baseURL + path + temp, {
    method,
    headers: {
      "content-type": "text/plain; charset=UTF-8",
      ...headers,
    },
    body: body ? JSON.stringify(body) : null,
  }).then((res) => res.json());
};
